import request from "@/utils/request";
export const service = () => {
  return !!JSON.parse(localStorage.$loginInfo).tenantId ? "/event" : "/ttevent";
};
//'/order/getOrderInfo'
export function queryFlowStartLink(query) {
  return request({
    url: service() + "/flow/alarm/queryFlowStartLink",
    method: "post",
    data: query,
  });
}
// /video/getVideoPlaybackUrl
export function genDefaultFlowInfo(data) {
  return request({
    data,
    url: service() + `/flow/alarm/genDefaultFlowInfo`,
    method: "post",
  });
}

// /flow/alarm/getFlow
export function getFlow(data) {
  return request({
    data,
    url: service() + `/flow/alarm/getFlow`,
    method: "post",
  });
}
export function getFlowId(tenantId, warningSource, alarmCode) {
  let flowId = "";
  queryFlowStartLink({
    tenantId: tenantId,
    warningSource: warningSource,
    alarmCode: alarmCode,
  })
    .then((resp) => {
      if (resp.code == 200) {
        flowId = resp.data.flowId;
        return flowId;
      }
    })
    .catch(() => {
      genDefaultFlowInfo({ tenantId: tenantId }).then((result) => {
        if (result && result.code == 200) {
          let flowFlow = tenantId + "_" + warningSource;
          flowId = result.data[flowFlow];
          return flowId;
        }
      });
    });
}
